home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
libs
/
usergrouplib.lha
/
usergroup
/
getpwent.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
6KB
|
249 lines
RCS_ID_C="$Id: getpwent.c,v 2.2 1994/02/17 02:19:40 ppessi Exp $";
/*
* User database functions
*
* Author: ppessi <Pekka.Pessi@hut.fi>
*
* This file is part of the AmiTCP/IP usergroup.library
*
* Copyright © 1993 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
* Helsinki University of Technology, Finland.
*
* Created : Sun Nov 28 17:45:55 1993 ppessi
* Last modified: Thu Jan 27 12:14:02 1994 ppessi
*
* $Log: getpwent.c,v $
* Revision 2.2 1994/02/17 02:19:40 ppessi
* Saving before downgrading library
*
* Revision 2.1 1994/01/23 03:18:14 ppessi
* Updated the netinfo.device commands
*
* Revision 1.4 1994/01/21 08:13:47 ppessi
* Updated documentation
*
* Revision 1.3 1994/01/19 10:04:06 ppessi
* Added error checking
*
* Revision 1.2 94/01/15 05:40:43 ppessi
* Hard disk crash
*
* Revision 1.1 93/11/30 03:31:28 ppessi
* Initial revision
*/
/****** usergroup.library/getpwent *******************************************
NAME
getpwent, getpwnam, getpwuid, setpwent, endpwent
- password database operations
SYNOPSIS
#include <pwd.h>
pw = getpwuid(uid)
D0 D0
struct passwd *getpwuid(uid_t);
pw = getpwnam(name)
D0 A1
struct passwd *getpwnam(const char *);
pw = getpwent()
D0
struct passwd *getpwent(void);
setpwent()
void setpwent(void);
endpwent()
void endpwent(void);
FUNCTION
These functions operate on the user database via netinfo.device
interface. They provide convenient unix-compatible interface to the
password unit of the netinfo.device.
The local password database is stored in the file AmiTCP:db/passwd,
its format is described in netinfo.device/passwd. The entry
returned by each reading function is defined by the structure passwd
found in the include file <pwd.h>:
struct passwd
{
char *pw_name; \* Username *\
char *pw_passwd; \* Encrypted password *\
pid_t pw_uid; \* User ID *\
gid_t pw_gid; \* Group ID *\
char *pw_gecos; \* Real name etc *\
char *pw_dir; \* Home directory *\
char *pw_shell; \* Shell *\
};
The functions getpwnam() and getpwuid() search the password database
for the given login name or user uid, respectively, always returning
the first one encountered.
The getpwent() function sequentially reads the password database and
is intended for programs that wish to process the complete list of
users.
All three routines will open the password unit of netinfo.device for
reading, if necesssary.
The setpwent() function opens the password unit of netinfo.device.
The endpwent() function closes the password unit of netinfo.device.
It is recommended to call endpwent() if the program won't access
password database any more.
RESULTS
The functions getpwent(), getpwnam() and getpwuid() return a valid
pointer to a passwd structure on success and a null pointer if end
of database is reached or an error occurs. The functions endpwent()
and setpwent() have no return value.
ERRORS
[ENOENT] -- the netinfo.device could not be opened.
Other netinfo.device IO errors can be retrieved by ug_GetErr().
FILES
AmiTCP:db/passwd The password database file
SEE ALSO
getgrent(), netinfo.device/passwd
HISTORY
The functions getpwent(), getpwnam(), getpwuid(), setpwent() and
endpwent() functions appeared in Version 7 AT&T UNIX.
BUGS
These functions leave their results in an internal static object and
return a pointer to that object. Subsequent calls to these function
will modify the same object. If you need re-entrant operation, you
should use directly the netinfo.device.
COMPATIBILITY
The BSD passwd database handling routines setpwfile() and
setpassent() are fairly useless in a networked environment and they
are not implemented.
*****************************************************************************
*
*/
#include "base.h"
#include "libfunc.h"
static short done_set_ent = 0;
SAVEDS ASM void R_endpwent(void)
{
ObtainSemaphore(ni_lock);
done_set_ent = 0;
CloseNIUnit(NETINFO_PASSWD_UNIT);
ReleaseSemaphore(ni_lock);
}
SAVEDS ASM void R_setpwent(void)
{
struct NetInfoReq *nreq;
ObtainSemaphore(ni_lock);
if (nreq = OpenNIUnit(NETINFO_PASSWD_UNIT)) {
nreq->io_Command = CMD_RESET;
myDoIO(nreq);
done_set_ent = 1;
} else {
SetDeviceErr();
}
ReleaseSemaphore(ni_lock);
}
SAVEDS ASM struct passwd *R_getpwent(void)
{
struct NetInfoReq *nreq;
struct passwd *pw = NULL;
ObtainSemaphore(ni_lock);
if (nreq = OpenNIUnit(NETINFO_PASSWD_UNIT)) {
/* do setpwent() if necessary */
if (!done_set_ent) {
nreq->io_Command = CMD_RESET;
myDoIO(nreq);
done_set_ent = 1;
}
nreq->io_Command = CMD_READ;
if (myDoIO(nreq) == 0) {
pw = (struct passwd *)nreq->io_Data;
} else {
SetDeviceErr();
}
} else {
SetDeviceErr();
}
ReleaseSemaphore(ni_lock);
return pw;
}
SAVEDS ASM struct passwd *R_getpwuid(REG(d0) uid_t uid)
{
struct NetInfoReq *nreq;
struct passwd *pw = NULL;
ObtainSemaphore(ni_lock);
if (nreq = OpenNIUnit(NETINFO_PASSWD_UNIT)) {
pw = (struct passwd *)nreq->io_Data;
pw->pw_uid = uid;
nreq->io_Command = NI_GETBYID;
if (myDoIO(nreq) != 0) {
pw = NULL;
SetDeviceErr();
}
} else {
SetDeviceErr();
}
ReleaseSemaphore(ni_lock);
return pw;
}
SAVEDS ASM struct passwd *R_getpwnam(REG(a1) const char *name)
{
struct NetInfoReq *nreq;
struct passwd *pw = NULL;
if (name == NULL) {
SetErrno(EFAULT);
return NULL;
}
ObtainSemaphore(ni_lock);
if (nreq = OpenNIUnit(NETINFO_PASSWD_UNIT)) {
pw = (struct passwd *)nreq->io_Data;
pw->pw_name = (char *)name;
nreq->io_Command = NI_GETBYNAME;
if (myDoIO(nreq) != 0) {
pw = NULL;
SetDeviceErr();
}
} else {
SetDeviceErr();
}
ReleaseSemaphore(ni_lock);
return pw;
}